Ask a Question
Send an email to me.
 
Java Question and Answer Forums
JavaRanch Big Moose Saloon
Marcus Green's Discussion Forum
java.sun.com Forums, Chat and User Groups
Artima Java Answers Forum
 
Other Resources
Java Language Specification
Java Virtual Machine Specification
Java 2 Platform, Standard Edition, v 1.4.0 API Specification
 
Tutorials
Learning the Java Language
Operator Precedence Chart, Expressions, Statements, Blocks
Programming with Assertions
 
Answers: Certified Java Programmer Mock Exam
No.AnswerRemark
1j  None of the Above   
2b  d  g  h  strictfp  super  goto  native  Both "const" and "goto" are java keywords, but neither is used.  
3b  c  e  g  i  boolean  short  const  instanceof  goto  Both "const" and "goto" are java keywords, but neither is used.  
4e  None of the Above  String literals are declared using double quotes but all of the declarations here use single quotes.  
5d  Prints: 0  Member variables are initialized automatically. Type int variables are initialized to zero.  
6b  c  e  Compiler error at line 4.  Compiler error at line 5.  Compiler error at line 7.  The escape sequences are defined in section 3.10.6 of the Java Language Specification.  
7a  e  transient  volatile  Both "const" and "goto" are java keywords, but neither is used. Serializable, Runnable, Externalizable, and Cloneable are all interfaces. Thread.run is a method. The keywords transient and volatile are field modifiers.  
8a  b  c  d  g  i  j  k  byte  short  int  long  float  double  boolean  char   
9d  4  The literal, 1.0, is a double and can not be used to initialize a float without an explicit cast.  
10f  None of the Above  All of the declarations are legal. String b is a single quote followed by the letter A followed by another single quote. String C is the letter A. String D is the unicode character that represents the hexidecimal value abcd.  
11a  Prints: 1111111,177,127,7f  A byte is an 8 bit signed value. The left most bit is the sign bit. The sign bit is set to zero for positive numbers and is set to one for negative numbers. The most positive byte value is represented as a sign bit that is set to zero and all of the other bits set to one. The Integer.toBinaryString method does not print leading zeros. An eight bit binary value is represented as three octal digits. The first of the three digits represents the left most two bits of the binary value. In this case, the left most two bits are zero and one. The second octal digit represents the next three bits of the binary value. The last of the octal digits represents the right most three bits of binary value. Note that the Integer.toOctalString method does not print a leading zero as is required for an octal literal value. An eight bit binary value is represented as two hexadecimal digits. The left hex digit represents the left most bits of the binary value. The right hex digit represents the right most bits of the binary value.  
12b  Prints: 1010101,125,85,55  A byte is an 8 bit signed value. The left most bit is the sign bit. The sign bit is set to zero for positive numbers. An eight bit binary value is represented as three octal digits. The first of the three digits represents the left most two bits of the binary value including any leading zeros. Please note that Integer.toBinaryString does not include the leading zeros. The second octal digit represents the next three bits of the binary value. The last of the octal digits represents the right most three bits of binary value. An eight bit binary value is represented as two hexadecimal digits. The left hex digit represents the left most bits of the binary value. The right hex digit represents the right most bits of the binary value. The decimal value of 85 can be converted to binary as follows. 85=64+16+4+1=01010101  
13f  Compiler error.  A compiler error is generated by the attempt to assign the line feed character to char variable l. A unicode escape character should not be used to represent a linefeed or a carriage return. Instead, the escape sequence '\r' should be used to represent a carriage return, and '\n' should be used to represent a linefeed.  
14a  b  c  e  char a = 0x0041;  char b = '\u0041';  char c = 0101;  char e = (char)-1;  The primitive char type is unsigned so a negative int can not be assigned to a char without an explicit cast. The result of the explicit cast is not a negative value. Instead, it is interpreted as a positive value that is very large. To be precise, it is the maximum value of the primitive char type.  
15f  Prints: 80000000,7fffffff  An int is a 32 bit signed value. The left most bit is the sign bit. The sign bit is zero for positive numbers and one for negative numbers.  
16e  Run-time exception  The index is incremented before the array access expression is evaluated so the first element accessed is at index one instead of zero. An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an element past the end of the array.  
17e  f  Compiler error at line 5.  Compiler error at line 6.  The non-static field x can not be referenced from within a static method. The local variable y has not been initialized.  
18c  Prints: 0null  The numeric sum of variables a, b, c, d, and e is zero. The zero is converted to a string and concatenated with s.  
19d  Prints: 127 -128 -1 0  Bytes are stored as 8 bit two's complement signed integers. When an int primitive is cast to a byte, the three most significant bytes are discarded and only the least significant byte remains. The most significant bit of the remaining byte becomes the new sign bit.  

Copyright © 2002, Dan Chisholm
All rights reserved.
1